package com.wzd.mphelper.mphelpertest.service.impl;

import com.baomidou.mybatisplus.annotation.DbType;
import com.wzd.mphelper.mphelpertest.entity.LandPlantingInfo;
import com.wzd.mphelper.mphelpertest.mapper.LandPlantingInfoMapper;
import com.wzd.mphelper.mphelpertest.service.ILandPlantingInfoService;
import com.wzd.mphelper.mphelpertest.subtable.service.CustomServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author tanjl11
 * @date 2021/10/27 17:07
 */
@Service("landPlantingInfoService")
public class LandPlantingInfoServiceImpl extends CustomServiceImpl<LandPlantingInfoMapper, LandPlantingInfo> implements ILandPlantingInfoService {

    @Resource
    private LandPlantingInfoMapper landPlantingInfoMapper;


    @Override
    public void saveLandPlantingInfos(List<LandPlantingInfo> landPlantingInfos) {
        Map<String, List<LandPlantingInfo>> collect = landPlantingInfos.stream().collect(Collectors.groupingBy(LandPlantingInfo::suffix));
        for (Map.Entry<String, List<LandPlantingInfo>> listEntry : collect.entrySet()) {
            List<LandPlantingInfo> landPlantingInfoList = listEntry.getValue();
            landPlantingInfoMapper.insertBatch(landPlantingInfoList);
        }
    }
}
